﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UFSoft.UBF.Business;
using UFSoft.UBF.Eventing;
using UFIDA.U9.SM.Ship;
using UFIDA.U9.PM.PO;
using UFSoft.UBF.PL;
using UFIDA.U9.PM.Rcv;
using UFIDA.U9.SM.RMA;
using UFIDA.U9.SM.SO;
using UFIDA.U9.CBO.SCM.Customer;
using UFIDA.U9.PR.PurchaseRequest;
using UFSoft.UBF.Util.DataAccess;
using UFSoft.UBF.PL.Engine;


namespace UFIDA.U9.Cust.LS.PlugBE
{
    /// <summary>
    /// 爱发科
    /// 请购单控制单据类型
    /// </summary>
    class ProcessForPRToInsert : IEventSubscriber
    {
        //配置XX.sub.xml文件放置到portal/bin下，dll文件放置到portal/ApplicationServer/Libs下
        public void Notify(params object[] args)
        {

            if (args == null || args.Length == 0 || !(args[0] is UFSoft.UBF.Business.EntityEvent)) return;
            BusinessEntity.EntityKey key = ((UFSoft.UBF.Business.EntityEvent)args[0]).EntityKey;

            if (key == null || key.GetEntity() == null) return;


            //请购
            UFIDA.U9.PR.PurchaseRequest.PR pr = key.GetEntity() as UFIDA.U9.PR.PurchaseRequest.PR;
            if (pr == null) return;

            #region 当请单单据类为 工序委外请购 输入的料号必需是132开头

            if (pr.Status == PR.PurchaseRequest.PRStatusEnum.OpenOpen)
            {
                //当请单单据类为 工序委外请购 输入的料号必需是132开头 
                if (pr.PRDocType.Code == "PR3"|| pr.PRDocType.Code == "PR7")
                {
                    foreach (var line in pr.PRLineList)
                    {
                        if (!(line.ItemInfo.ItemCode.StartsWith("132-") || line.ItemInfo.ItemCode.StartsWith("232-")))
                        {
                            throw new Exception("工序委外请购料号必需是132或者232开始");

                        }
                    }

                }
            }

            #endregion
        }
    }
}
